package com.mochasoft.shangchm.analyzer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class AnalyzerFactory {

	private static Map analyzerMap;

	private static AnalyzerFactory factory;

	public static synchronized AnalyzerFactory getInstance() {
		if (factory == null)
			factory = new AnalyzerFactory();
		return factory;
	}

	private AnalyzerFactory() {
		analyzerMap = new LinkedHashMap();
	}

	public void addAnalyzer(String key, Analyzer analyzer) {
		analyzerMap.put(key, analyzer);
	}

	public void removeAnalyzer(String key) {
		analyzerMap.remove(key);
	}

	public Analyzer getAnalyzer(String key) {
		return (Analyzer) analyzerMap.get(key);
	}

	public Map getAnalyzers() {
		return analyzerMap;
	}
	
	public Map getAnalyzers(Set keys) {
		Map map = new HashMap();
		Iterator iter = keys.iterator();
		while(iter.hasNext()){
			String key = (String)iter.next();
			Analyzer analyzer =(Analyzer) analyzerMap.get(key);
			if(analyzer!=null)
			map.put(key, analyzer);
		}
		return map;
	}

	public void addAnalyzers(Map analyzers) {
		analyzerMap.putAll(analyzers);
	}
	

}
